﻿#include "TcpListener.h"
#include <qthread.h>
#include "qdebug.h"

#include "TcpIOer.h"
#include "TcpThread.h"

TcpListener::TcpListener() : QTcpServer(), ObjAutoInject()
{
  qRegisterMetaType<qintptr>("qintptr");
  qRegisterMetaType<QTcpSocket::SocketState>("QTcpSocket::SocketState");
  qRegisterMetaType<QTcpSocket::OpenMode>("QTcpSocket::OpenMode");
  qRegisterMetaType<TcpListener::PrivateSignalClass>("TcpListener::PrivateSignalClass");
}
TcpListener::~TcpListener()
{
}

void TcpListener::incomingConnection(qintptr socketDescriptor)
{
  logSaver->saveLog("tcpListener,new tcp connection incoming");
  TcpThread* tcpThread=new TcpThread();
  connect(tcpThread,&TcpThread::signal_newTcpCreated,this,&TcpListener::signal_newConnection);
  connect(tcpThread,&TcpThread::signal_newTcpCreated,[=](){
      disconnect(tcpThread,&TcpThread::signal_newTcpCreated,this,&TcpListener::signal_newConnection);});
  tcpThread->startNewTcp(socketDescriptor);
}
